package com.example.mybatisdemo2.demos.web.mapper;

import com.example.mybatisdemo2.demos.web.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Q
 * @create 2025-06-09-16:49
 */
//方法定义
@Mapper
public interface UserInfoMapper {
    @Select("select * from userinfo where id = ${value}")
    UserInfo queryUserInfo(Integer id);

    @Select("select * from userinfo where username = '${username}'")
    UserInfo queryUserInfoByName(String username);
    //演示SQL注入
//    @Select("select * from userinfo where username= #{username} and password = #{password}")
//    List<UserInfo> queryUserByNameAndPassword(String username, String password);
//
//
//    @Select("select * from userinfo where username= '${username}' and password = '${password}'")
//    List<UserInfo> queryUserByNameAndPassword2(String username, String password);
    //排序
    @Select("select * from userinfo order by id ${order}")
    List<UserInfo> queryUserInfoByOrder(String order);
    //like查询
    @Select("select * from userinfo where username like CONCAT('%',#{name},'%')")
    List<UserInfo> queryUserInfoByLike(String name);
//    //if语句数据插入
//    @Insert("<script>insert into userinfo(username,password," +
//            "<if test='age!=null'>age,</if> " +
//            "gender,phone) " +
//            "values (#{username},#{password}," +
//            "<if test='age!=null'>#{age},</if>" +
//            "#{gender},#{phone})" +
//            "</script>")
//    Integer insertByCondition(UserInfo userInfo);
}
